package com.cms.common.model.entity;

import com.cms.common.utils.TranslateUtil;
import lombok.Data;

import javax.persistence.*;
import java.util.List;

/**
 * 文章
 */
@Entity
@Data
public class Article extends BaseEntity {


    @OneToMany(targetEntity = Translate.class, cascade = {CascadeType.ALL})
    private List<Translate> titleTranslates = null;//

    @Transient
    private Translate titleTranslate = null;//

    @OneToMany(targetEntity = Translate.class, cascade = {CascadeType.ALL})
    private List<Translate> contentTranslates = null;//

    @Transient
    private Translate contentTranslate = null;//


    @ManyToOne(targetEntity = ArticleCategory.class)
    @JoinColumn(name = "category_id", referencedColumnName = "id")
    private ArticleCategory category = null;//

    public Translate getTitleTranslate() {
        return TranslateUtil.getContentTranslate(titleTranslates);
    }

    public Translate getContentTranslate() {
        return TranslateUtil.getContentTranslate(contentTranslates);
    }
}
